{% extends 'base.tpl' %}

{% block title %} 端口扫描 {% endblock %}

{% block custom_css %} {% endblock %}

{% block page_guider %}
    <ul class="layui-nav">
        <li class="layui-nav-item"><a href="/web/">基础信息</a></li>
        <li class="layui-nav-item layui-this"><a href="/web/portscan">端口扫描</a></li>
        <li class="layui-nav-item"><a href="/web/webside">旁站扫描</a></li>
        <li class="layui-nav-item"><a href="/web/infoleak">信息泄漏</a></li>
      <li class="layui-nav-item">
        <a href="javascript:;">了解更多</a>
        <dl class="layui-nav-child"> <!-- 二级菜单 -->
          <dd><a href="https://blog.dyboy.cn/develop/threatscan.html" target="_blank">使用帮助</a></dd>
          <dd><a href="/static/img/dashang.png" target="_blank">打赏支持</a></dd>
          <dd><a href="https://wpa.qq.com/msgrd?v=3&uin=1099718640&site=qq&menu=yes" target="_blank" title="发起QQ会话">联系作者</a></dd>
          <dd><a href="https://wpa.qq.com/msgrd?v=3&uin=1099718640&site=qq&menu=yes" target="_blank" title="发起QQ会话">意见反馈/指纹提交</a></dd>
        </dl>
      </li>
    </ul>
{% endblock %}

{% block content %}
    <!-- 产品信息 -->
    <div class="threatscan-title">
        <h1> 端口扫描 </h1>
        <p>扫描常见398个端口，填写IP，扫描结果更准确哦！</p>
    </div>

    <!-- 表单框/提交网址 -->
    <div class="threatscan-search">
        <div class="layui-form">
            <div class="layui-form-item">
              <div class="layui-input-inline">
                <input type="text" name="siteip" minlength="15" maxlength="15" required="" lay-verify="required" lay-vertype="tips" placeholder="请填写正确的IP地址" autocomplete="off" class="layui-input">
              </div>
              <button class="layui-btn layui-bg-blue layui-btn-lg btn-scan">扫描端口</button>
            </div>
        </div>
    </div>

    <!-- 结果展示区 -->
    <div class="threatscan-result" style="display: none;margin-bottom: 150px;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
          <legend>查询结果</legend>
        </fieldset>

          <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
              <div class="layui-card">
                <table class="layui-table" lay-even="" lay-skin="nob" style="width: 100%;margin: 10px 0;">
                    <tbody>
                        <tr>
                            <td>
                                多线程扫描，预计请等待<span>10</span>>s &nbsp;<i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>
                            </td>
                        </tr>
                    </tbody>
                </table>
              </div>
            </div>
          </div>
    </div>
{% endblock %}

{% block page_js %}
        function get_port_info(ip) {
            $.post('/api/portscan',{
                ip: ip
            }, function(data){
                if(data.code != 200) {
                    $('.threatscan-result').hide();
                    layer.msg(data.data);
                }
                else{
                    $('tbody tr:first').html("<tr><td><strong>端口</strong></td><td><strong>协议/服务</strong></td></tr>");
                    var tr_html = ''
                    $.each(data.data, function(index, obj) {
                        let obj_arr = obj.split(':');
                        $('tbody').append("<tr><td>" + obj_arr[1] + "</td><td>" + obj_arr[0] + "</td></tr>");
                    });
                    layer.msg('查询成功');
                }

                $(".btn-scan").text('重新扫描');
                $('.btn-scan').attr('disabled', false);
            });
        }

        $(function () {
            $(".btn-scan").click(function () {
                $(this).attr('disabled', true);
                $(this).text('请稍等');
                var domain = $('input[name=siteip]').val();
                if(domain){
                    // 校验当前网址是否正确/符合规范
                    // coding ...
                    $('tbody').html('<tr> <td> 多线程扫描，预计请等待<span>10</span>s &nbsp;<i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i></td> </tr>');
                    $('.threatscan-result').show();
                    get_port_info(domain);
                } else {
                    $('input[name=siteip]').val('');
                    layer.msg('请输入正确的IP，例如：1.1.1.1');
                    $(".btn-scan").text('查询');
                    $(".btn-scan").attr('disabled', false);
                }
            });
        });
    });

{% endblock %}

